<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>结算中心 - GameHub | 学号-姓名-实验5</title>
    <style>
        /* 使用与购物车页面相同的CSS变量和基础样式 */
        :root {
            --primary-color: #6c5ce7;
            --secondary-color: #a29bfe;
            --dark-color: #2d3436;
            --light-color: #f5f6fa;
            --success-color: #00b894;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background-color: var(--light-color);
            color: var(--dark-color);
        }
        
        header {
            background-color: var(--primary-color);
            color: white;
            padding: 1rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .logo {
            font-size: 1.8rem;
            font-weight: bold;
        }
        
        nav ul {
            display: flex;
            list-style: none;
        }
        
        nav ul li {
            margin-left: 1.5rem;
        }
        
        nav ul li a {
            color: white;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        
        nav ul li a:hover {
            color: var(--secondary-color);
        }
        
        .user-actions a {
            color: white;
            text-decoration: none;
            margin-left: 1rem;
        }

        footer {
            background-color: var(--dark-color);
            color: white;
            padding: 2rem;
            margin-top: 2rem;
        }
        
        .footer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 2rem;
            max-width: 1200px;
            margin: 0 auto;
        }
        
        .footer-section h3 {
            margin-bottom: 1rem;
            font-size: 1.2rem;
        }
        
        .footer-section ul {
            list-style: none;
        }
        
        .footer-section ul li {
            margin-bottom: 0.5rem;
        }
        
        .footer-section ul li a {
            color: #ddd;
            text-decoration: none;
            transition: color 0.3s ease;
        }
        
        .footer-section ul li a:hover {
            color: white;
        }
        
        .copyright {
            text-align: center;
            margin-top: 2rem;
            padding-top: 1rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            max-width: 1200px;
            margin-left: auto;
            margin-right: auto;
        }

        /* 响应式设计 - 页脚 */
        @media (max-width: 768px) {
            .footer-content {
                grid-template-columns: 1fr 1fr;
            }
        }
        
        /* 结算页面特定样式 */
        .checkout-container {
            max-width: 1200px;
            margin: 2rem auto;
            display: flex;
            gap: 2rem;
        }
        
        .order-summary {
            flex: 2;
            background-color: white;
            border-radius: 8px;
            padding: 1.5rem;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
        }
        
        .payment-section {
            flex: 1;
            background-color: white;
            border-radius: 8px;
            padding: 1.5rem;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            height: fit-content;
        }
        
        .section-title {
            font-size: 1.5rem;
            margin-bottom: 1.5rem;
            padding-bottom: 1rem;
            border-bottom: 1px solid #eee;
        }
        
        .order-item {
            display: flex;
            border-bottom: 1px solid #eee;
            padding: 1rem 0;
            align-items: center;
        }
        
        .order-item:last-child {
            border-bottom: none;
        }
        
        .item-image {
            width: 120px;
            height: 80px;
            margin-right: 1rem;
        }
        
        .item-image img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: 4px;
        }
        
        .item-details {
            flex: 1;
        }
        
        .item-title {
            font-weight: 600;
            margin-bottom: 0.5rem;
        }
        
        .item-price {
            color: var(--primary-color);
            font-weight: bold;
        }
        
        .payment-method {
            margin-bottom: 2rem;
        }
        
        .payment-option {
            display: flex;
            align-items: center;
            gap: 1rem;
            padding: 0.8rem;
            border: 1px solid #eee;
            border-radius: 4px;
            margin-bottom: 1rem;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .payment-option:hover {
            border-color: var(--secondary-color);
        }
        
        .payment-option input[type="radio"] {
            display: none;
        }
        
        .payment-option input[type="radio"]:checked + label {
            border-color: var(--primary-color);
            background-color: rgba(108, 92, 231, 0.05);
        }
        
        .payment-option img {
            width: 40px;
            height: 40px;
        }
        
        .total-section {
            margin-top: 2rem;
            padding-top: 1.5rem;
            border-top: 1px solid #eee;
        }
        
        .total-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 1rem;
        }
        
        .final-total {
            font-weight: bold;
            font-size: 1.2rem;
            margin: 1.5rem 0;
            padding-top: 1rem;
            border-top: 1px solid #eee;
            color: var(--primary-color);
        }
        
        .btn {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s ease;
            width: 100%;
            text-align: center;
            display: block;
            text-decoration: none;
        }
        
        .btn-primary {
            background-color: var(--primary-color);
            color: white;
            margin-bottom: 1rem;
        }
        
        .btn-primary:hover {
            background-color: #5649c0;
        }
        
        .btn-secondary {
            background-color: var(--dark-color);
            color: white;
        }
        
        .btn-secondary:hover {
            background-color: #1a1e1f;
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .checkout-container {
                flex-direction: column;
            }
            
            .order-item {
                flex-direction: column;
                align-items: flex-start;
            }
            
            .item-image {
                margin-bottom: 1rem;
            }
        }
    </style>
</head>
<body>
    <!-- 头部导航 - 与购物车页面一致 -->
    <header>
        <div class="logo">GameHub</div>
        <nav>
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="#">游戏商城</a></li>
                <li><a href="#">特惠活动</a></li>
                <li><a href="#">新游预告</a></li>
                <li><a href="#">社区论坛</a></li>
            </ul>
        </nav>
        <div class="user-actions">
            <a href="#" id="login-btn">登录</a>
            <a href="#" id="register-btn">注册</a>
            <a href="cart.html"><i class="fas fa-shopping-cart"></i> 购物车</a>
        </div>
    </header>

    <!-- 结算页面主体 -->
    <div class="container">
        <h1 class="cart-title">结算中心</h1>
        
        <div class="checkout-container">
            <!-- 订单摘要 -->
            <div class="order-summary">
                <h2 class="section-title">订单详情</h2>
                
                <!-- 动态生成的订单商品列表 -->
                <div id="order-items"></div>
                
                <!-- 配送信息 -->
                <div class="shipping-info" style="margin-top: 2rem; padding: 1rem; background-color: var(--light-color); border-radius: 4px;">
                    <h3 style="margin-bottom: 0.5rem;">配送信息</h3>
                    <p>收货地址：默认地址</p>
                    <p>联系电话：159-****-7617</p>
                    <button class="btn btn-secondary" style="width: auto; margin-top: 1rem; padding: 0.5rem 1rem;">修改</button>
                </div>
            </div>
            
            <!-- 支付信息 -->
            <div class="payment-section">
                <h2 class="section-title">支付方式</h2>
                
                <div class="payment-method">
                    <div class="payment-option">
                        <input type="radio" id="wechat-pay" name="payment" value="wechat" checked>
                        <label for="wechat-pay" style="display: flex; align-items: center; width: 100%; cursor: pointer;">
                            <img src="images/12.png" alt="微信支付">
                            <span>微信支付</span>
                        </label>
                    </div>
                    
                    <div class="payment-option">
                        <input type="radio" id="alipay" name="payment" value="alipay">
                        <label for="alipay" style="display: flex; align-items: center; width: 100%; cursor: pointer;">
                            <img src="images/13.png" alt="支付宝">
                            <span>支付宝</span>
                        </label>
                    </div>
                    
                    <div class="payment-option">
                        <input type="radio" id="bank-card" name="payment" value="bank">
                        <label for="bank-card" style="display: flex; align-items: center; width: 100%; cursor: pointer;">
                            <img src="images/14.png" alt="银行卡支付">
                            <span>银行卡支付</span>
                        </label>
                    </div>
                </div>
                
                <!-- 订单总额 -->
                <div class="total-section">
                    <div class="total-row">
                        <span>商品总价</span>
                        <span id="subtotal">¥0.00</span>
                    </div>
                    <div class="total-row">
                        <span>折扣优惠</span>
                        <span id="discount">-¥0.00</span>
                    </div>
                    <div class="total-row">
                        <span>运费</span>
                        <span>¥0.00</span>
                    </div>
                    <div class="final-total">
                        <span>应付总额</span>
                        <span id="total">¥0.00</span>
                    </div>
                    
                    <button class="btn btn-primary" onclick="placeOrder()">立即支付</button>
                    <a href="cart.html" class="btn btn-secondary">返回购物车</a>
                </div>
            </div>
        </div>
    </div>

    <!-- 页脚 - 与购物车页面一致 -->
    <footer>
        <div class="footer-content">
            <div class="footer-section">
                <h3>关于我们</h3>
                <ul>
                    <li><a href="#">公司简介</a></li>
                    <li><a href="#">团队介绍</a></li>
                    <li><a href="#">联系方式</a></li>
                    <li><a href="#">加入我们</a></li>
                </ul>
            </div>
            <div class="footer-section">
                <h3>客户服务</h3>
                <ul>
                    <li><a href="#">帮助中心</a></li>
                    <li><a href="#">支付方式</a></li>
                    <li><a href="#">配送方式</a></li>
                    <li><a href="#">退换政策</a></li>
                </ul>
            </div>
            <div class="footer-section">
                <h3>法律信息</h3>
                <ul>
                    <li><a href="#">用户协议</a></li>
                    <li><a href="#">隐私政策</a></li>
                    <li><a href="#">版权声明</a></li>
                    <li><a href="#">知识产权</a></li>
                </ul>
            </div>
            <div class="footer-section">
                <h3>关注我们</h3>
                <ul>
                    <li><a href="#">微信公众号</a></li>
                    <li><a href="#">微博</a></li>
                    <li><a href="#">B站</a></li>
                    <li><a href="#">抖音</a></li>
                </ul>
            </div>
        </div>
        <div class="copyright">
            <p>© 2023 GameHub游戏购物平台. 版权所有. 学号：123456 姓名：张三</p>
        </div>
    </footer>

    <!-- JavaScript -->
    <script>
        // 获取购物车数据
        const cart = JSON.parse(localStorage.getItem('gamehub-cart')) || [];
        const orderItemsContainer = document.getElementById('order-items');
        const subtotalElement = document.getElementById('subtotal');
        const discountElement = document.getElementById('discount');
        const totalElement = document.getElementById('total');

        // 渲染订单商品
        function renderOrderItems() {
            if (cart.length === 0) {
                orderItemsContainer.innerHTML = `
                    <div class="empty-cart">
                        <div class="empty-cart-icon">🛒</div>
                        <div class="empty-cart-message">您的购物车是空的</div>
                        <a href="index.html" class="btn btn-primary">去逛逛</a>
                    </div>
                `;
                return;
            }
            
            let html = '';
            let subtotal = 0;

            cart.forEach(item => {
                subtotal += item.price * item.quantity;
                html += `
                    <div class="order-item">
                        <div class="item-image">
                            <img src="${item.image}" alt="${item.title}">
                        </div>
                        <div class="item-details">
                            <h3 class="item-title">${item.title}</h3>
                            <div class="item-price">¥${(item.price * item.quantity).toFixed(2)}</div>
                            <p>数量：${item.quantity}</p>
                        </div>
                    </div>
                `;
            });

            orderItemsContainer.innerHTML = html;
            updateTotal(subtotal);
        }

        // 更新订单总额
        function updateTotal(subtotal) {
            const discount = subtotal > 300 ? 50 : 0;
            const total = subtotal - discount;

            subtotalElement.textContent = `¥${subtotal.toFixed(2)}`;
            discountElement.textContent = `-¥${discount.toFixed(2)}`;
            totalElement.textContent = `¥${total.toFixed(2)}`;
        }

        // 支付功能
        function placeOrder() {
            const paymentMethod = document.querySelector('input[name="payment"]:checked').value;
            alert(`已选择${paymentMethod === 'wechat' ? '微信支付' : paymentMethod === 'alipay' ? '支付宝支付' : '银行卡支付'}，应付金额：${totalElement.textContent}`);
            
            // 实际开发中应添加支付接口调用逻辑
            // 此处可添加清空购物车逻辑
            localStorage.removeItem('gamehub-cart');
            window.location.href = 'payment-success.html'; // 支付成功页面
        }

        // 页面加载时初始化
        document.addEventListener('DOMContentLoaded', () => {
            renderOrderItems();
        });

        // 监听购物车数据变化
        window.addEventListener('storage', (event) => {
            if (event.key === 'gamehub-cart') {
                const newCart = JSON.parse(event.newValue || '[]');
                cart.splice(0, cart.length, ...newCart);
                renderOrderItems();
            }
        });
    </script>
</body>
</html>